﻿# CMakeList.txt: CMakeProjectOpenssh 的 CMake 项目，在此处包括源代码并定义
# 项目特定的逻辑。
#
cmake_minimum_required (VERSION 3.8)
add_compile_options(-std=c++11)
#file(GLOB OPEN_SSH_SRC_LIST ./*.cpp ./*.h ./*/*.cpp ./*/*.h ./3rd/zlib1.2.11/*.c ./3rd/zlib1.2.11/*.h ./3rd/zlib1.2.11/*.cpp)  #./3rd/openssl/include/openssl/*.h)
file(GLOB OPEN_SSH_SRC_LIST ./*.cpp ./*.h ./tests/*.cpp ./tests/*.h ./3rd/zlib1.2.11/*.c ./3rd/zlib1.2.11/*.h ./3rd/zlib1.2.11/*.cpp)  #./3rd/openssl/include/openssl/*.h)

project ("CMakeProjectOpenssh")

# 将源代码添加到此项目的可执行文件。
add_executable (CMakeProjectOpenssh "${OPEN_SSH_SRC_LIST}")

set(openssl_client_src ${CMAKE_CURRENT_SOURCE_DIR}/testsssl/TestClientSSL.cpp)
add_executable(testOpenClientSSL ${openssl_client_src})

set(openssl_server_src ${CMAKE_CURRENT_SOURCE_DIR}/testsssl/TestServerSSL.cpp)
add_executable(testOpenServerSSL ${openssl_server_src})

if (CMAKE_VERSION VERSION_GREATER 3.12)
  set_property(TARGET CMakeProjectOpenssh PROPERTY CXX_STANDARD 20)
endif()

#openssl lib类库由openssl-src编译而来
#

#add_subdirectory(./3rd/openssl-src)

#D:\video-technology\vcpkg\installed\x64-windows\debug\lib
#find_package(ZLIB REQUIRED)



if (WIN32)
	add_subdirectory(./3rd/openssl-src)
	set(OPENSSL_INC_DIR ${CMAKE_SOURCE_DIR}/3rd/openssl/include)
	set(OPENSSL_LIB_DIR ${CMAKE_SOURCE_DIR}/3rd/openssl/lib)
	include_directories(${OPENSSL_INC_DIR})
	#link_directories(${OPENSSL_LIB_DIR})
	#link_libraries(libcrypto-1_1-x64.lib libcrypto-1_1-x64.lib)
	#set(SPDLOG_LIB_DIR  ${CMAKE_SOURCE_DIR}/thirdparty/spdlog/libs)
	#target_link_libraries(Terminal PUBLIC Threads::Threads yxtnets spdlog sqlite_raw SQLiteCpp)
	#message(STATUS ">>==libcrypto_LIB_FILE==${CMAKE_CURRENT_SOURCE_DIR}/3rd/openssl/lib/libcrypto-1_1-x64.lib")

	#https://blog.csdn.net/Kelvin_Yan/article/details/105078461
	set(OPENSSL_INC_DIR2 ${CMAKE_SOURCE_DIR}/3rd/openssl/include)

	#target_link_libraries(CMakeProjectOpenssh PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/3rd/openssl/lib/libcrypto-1_1-x64.lib ${CMAKE_CURRENT_SOURCE_DIR}/3rd/openssl/lib/libssl-1_1-x64.lib  wsock32 ws2_32 crypt32.lib)
	set(OPENSSL_SSL_LIB ${CMAKE_CURRENT_SOURCE_DIR}/out/build/x64-debug/3rd/openssl-src/ssl/libssl-1_1-x64.lib)
	set(OPENSSL_CRYPTO_LIB ${CMAKE_CURRENT_SOURCE_DIR}/out/build/x64-debug/3rd/openssl-src/crypto/libcrypto-1_1-x64.lib)
	#target_link_libraries(CMakeProjectOpenssh PRIVATE ${OPENSSL_SSL_LIB} ${OPENSSL_CRYPTO_LIB}  wsock32 ws2_32 crypt32.lib ZLIB::ZLIB)
	target_link_libraries(CMakeProjectOpenssh PRIVATE ${OPENSSL_SSL_LIB} ${OPENSSL_CRYPTO_LIB}  wsock32 Ws2_32.lib  crypt32.lib)
	target_link_libraries(testOpenClientSSL PRIVATE ${OPENSSL_SSL_LIB} ${OPENSSL_CRYPTO_LIB}  wsock32 Ws2_32.lib  crypt32.lib)
	target_link_libraries(testOpenServerSSL PRIVATE ${OPENSSL_SSL_LIB} ${OPENSSL_CRYPTO_LIB}  wsock32 Ws2_32.lib  crypt32.lib)

#target_link_libraries(CMakeProjectOpenssh PRIVATE libssl-1_1-x64)
else()
	#linux-x86架构
	set(OPENSSL_INC_DIR ${CMAKE_SOURCE_DIR}/3rd/openssl_linux/include)
	set(OPENSSL_LIB_DIR ${CMAKE_SOURCE_DIR}/3rd/openssl_linux/lib)
	include_directories(${OPENSSL_INC_DIR})

	#https://stackoverflow.com/questions/26259335/error-in-libcrypto-a-when-make-c-code
	target_link_libraries(CMakeProjectOpenssh PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/3rd/openssl_linux/lib/libcrypto.a ${CMAKE_CURRENT_SOURCE_DIR}/3rd/openssl_linux/lib/libssl.a pthread -ldl)
endif()

# TODO: 如有需要，请添加测试并安装目标。
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/3rd/openssl/bin/private_key.pem DESTINATION ${CMAKE_BINARY_DIR}/)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/3rd/openssl/bin/certificate.crt DESTINATION ${CMAKE_BINARY_DIR}/)
